﻿using System;
using UnityEngine;

// Token: 0x02000019 RID: 25
public class LevitatorScript : MonoBehaviour
{
	// Token: 0x06000073 RID: 115 RVA: 0x0000D3C8 File Offset: 0x0000B5C8
	private void Start()
	{
		this.body = base.GetComponent<BodyScript>();
		GameObject gameObject = Object.Instantiate<GameObject>(Resources.Load<GameObject>("GrabLine"), Vector2.zero, Quaternion.identity);
		this.grabLine = gameObject.GetComponent<LineRenderer>();
	}

	// Token: 0x06000074 RID: 116 RVA: 0x0000D40C File Offset: 0x0000B60C
	private void Update()
	{
		if (Input.GetMouseButtonDown(1) && this.body.health >= 0f)
		{
			Collider2D collider2D = Physics2D.OverlapCircle(Camera.main.ScreenToWorldPoint(Input.mousePosition), 0.1f, LayerMask.GetMask(new string[]
			{
				"Default",
				"Grunt"
			}));
			if (collider2D && collider2D.attachedRigidbody && !collider2D.attachedRigidbody.isKinematic && !this.body.limbCols.Contains(collider2D))
			{
				this.levitated = collider2D.attachedRigidbody;
				if (!collider2D.gameObject.GetComponent<DamageReceiver>())
				{
					this.localGrabPos = collider2D.transform.InverseTransformPoint(Camera.main.ScreenToWorldPoint(Input.mousePosition));
				}
				else
				{
					this.localGrabPos = Vector2.zero;
				}
				if (collider2D.GetComponent<WeaponScript>())
				{
					this.heldWep = collider2D.GetComponent<WeaponScript>();
					this.originallyPickupable = this.heldWep.pickupable;
					this.heldWep.pickupable = false;
					if (this.heldWep.GetComponent<DamagingObject>().currentOwner)
					{
						this.heldWep.GetComponent<DamagingObject>().currentOwner.DropWeapon();
					}
				}
			}
		}
		if ((this.levitated && this.body.health < 0f) || Input.GetMouseButtonUp(1))
		{
			if (this.heldWep)
			{
				this.heldWep.pickupable = this.originallyPickupable;
			}
			this.levitated = null;
			this.heldWep = null;
		}
		if (this.levitated)
		{
			this.grabLine.SetPosition(0, Camera.main.ScreenToWorldPoint(Input.mousePosition));
			this.grabLine.SetPosition(1, this.levitated.transform.TransformPoint(this.localGrabPos));
			this.grabLine.enabled = true;
			return;
		}
		this.grabLine.enabled = false;
	}

	// Token: 0x06000075 RID: 117 RVA: 0x0000D638 File Offset: 0x0000B838
	private void FixedUpdate()
	{
		if (this.levitated)
		{
			Vector2 vector = Camera.main.ScreenToWorldPoint(Input.mousePosition) - this.levitated.transform.TransformPoint(this.localGrabPos);
			MonoBehaviour.print(vector);
			this.levitated.AddForceAtPosition(vector * this.body.overallForce * 5.3f, this.levitated.transform.TransformPoint(this.localGrabPos));
			this.levitated.velocity *= 0.93f;
			this.levitated.angularVelocity *= 0.93f;
			if (this.heldWep && this.heldWep.GetComponent<DissapearHandler>())
			{
				this.heldWep.GetComponent<SpriteRenderer>().color = Color.white;
				Object.Destroy(this.heldWep.GetComponent<DissapearHandler>());
			}
		}
	}

	// Token: 0x0400013E RID: 318
	private BodyScript body;

	// Token: 0x0400013F RID: 319
	public Rigidbody2D levitated;

	// Token: 0x04000140 RID: 320
	public Vector2 localGrabPos;

	// Token: 0x04000141 RID: 321
	private LineRenderer grabLine;

	// Token: 0x04000142 RID: 322
	private bool originallyPickupable;

	// Token: 0x04000143 RID: 323
	private WeaponScript heldWep;
}
